<?php
// +---------------------------------------------------------------------------------
// | ApiAdmin [ JUST FOR API ]
// +---------------------------------------------------------------------------------
// | Copyright (c) 2017~2020 https://www.apiadmin.org/ All rights reserved.
// +---------------------------------------------------------------------------------
// | Licensed ( https://gitee.com/apiadmin/ApiAdmin/blob/master/LICENSE.txt )
// +---------------------------------------------------------------------------------
// | Author: zhaoxiang <zhaoxiang051405@gmail.com>
// +---------------------------------------------------------------------------------

use think\facade\Route;

// 定义中间件组
$middlewareGroups = [
    'api' => [
        app\middleware\ApiLog::class,
        app\middleware\ApiResponse::class
    ],
    'auth' => [
        app\middleware\ApiLog::class,
        app\middleware\ApiLogin::class,
        app\middleware\ApiResponse::class
    ]
];

// 定义路由配置
$routes = [
    // 不需要登录的接口
    'user/login' => ['POST', 'api.user/login', 'api'],
    'railway/lists' => ['GET', 'api.railway/lists', 'api'],
    'user/logout' => ['POST', 'api.user/logout', 'api'],
    'user/list' => ['GET', 'api.user/list', 'auth'],
    // 需要登录的接口
    'user/upload' => ['POST', 'api.user/upload', 'auth'],

    'checkType/lists' => ['GET', 'api.checkType/lists', 'auth'],
    'station/stations' => ['GET', 'api.station/stations', 'auth'],
    'station/detail' => ['GET', 'api.station/detail', 'auth'],
    'railway/detail' => ['GET', 'api.railway/detail', 'auth'],
    'checkItem/lists' => ['GET', 'api.checkItem/lists', 'auth'],
    'railway/getAll' => ['GET', 'api.railway/getAll', 'auth'],
    'railway/record_info' => ['GET', 'api.railway/recordInfo', 'auth'],
    'railway/record' => ['GET', 'api.railway/record', 'auth'],
    // 'railway/check' => ['POST', 'api.railway/check', 'auth'],
    'user/userInfo' => ['GET', 'api.user/userInfo', 'auth'],
    'checkItem/check' => ['POST', 'api.checkItem/check', 'auth'],
    'checkItem/record' => ['GET', 'api.checkItem/record', 'auth'],
    'checkItem/record_info' => ['GET', 'api.checkItem/record_info', 'auth']
];

// 注册路由组
Route::group('api', function() use ($routes, $middlewareGroups) {
    // 注册所有路由
    foreach ($routes as $path => $config) {
        list($method, $controller, $middlewareGroup) = $config;
        Route::rule($path, $controller, $method)
            ->middleware($middlewareGroups[$middlewareGroup]);
    }
    
    // 注册未匹配路由处理
    Route::miss('api.Miss/index');
});
